Fix example code for json::json_pointer initialization#4468
Merged
nlohmann merged 1 commit intonlohmann:developfrom May 22, 2025
Merged
Fix example code for json::json_pointer initialization#4468nlohmann merged 1 commit intonlohmann:developfrom
nlohmann merged 1 commit intonlohmann:developfrom
Conversation
Changed the example code in the documentation from copy initialization to direct initialization for `json::json_pointer`. This prevents compilation errors caused by the constructor being explicit.
|
This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions! |
2 tasks
nlohmann
pushed a commit
that referenced
this pull request
May 25, 2025
Changed the example code in the documentation from copy initialization to direct initialization for `json::json_pointer`. This prevents compilation errors caused by the constructor being explicit.
nlohmann
pushed a commit
that referenced
this pull request
May 25, 2025
Changed the example code in the documentation from copy initialization to direct initialization for `json::json_pointer`. This prevents compilation errors caused by the constructor being explicit. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In #4453, the compilation error of
json::json_pointer p = "/nested/one";is due to the implicit conversion, as the constructor forjson_pointeris markedexplicit(see following source code).json/include/nlohmann/detail/json_pointer.hpp
Lines 62 to 64 in b36f4c4
Removing the
explicitcan allows to compile and pass the test, but i think it it might violate the design intentions.Modification
Changed the example code in the documentation (https://json.nlohmann.me/features/json_pointer/#json-pointer-creation) from copy initialization to direct initialization.
Before
json::json_pointer p = "/nested/one";After
Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmanndirectory, runmake amalgamateto create the single-header filessingle_include/nlohmann/json.hppandsingle_include/nlohmann/json_fwd.hpp. The whole process is described here.